package net.chowda.castcluster.action.ajax;

import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.DefaultHandler;
import net.chowda.castcluster.util.CastClusterConfig;
import net.chowda.castcluster.action.ConfigAction;

import java.util.Map;

/**
 * action called by ajax config requests
 *
 * only deals with config we explicitly work out...
 * i.e. there are configurable items this action doesn't know about.
 */
public class EditConfigAction extends ConfigAction {
    @DefaultHandler
    public Resolution save() {
        CastClusterConfig config = CastClusterConfig.getInstance();

        Map<String,String> props = config.getGlobalProperties();
        String baseUrl = getBaseUrl();
        if(baseUrl.endsWith("/")) {
            baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
        }
        props.put(CastClusterConfig.BASE_URL, baseUrl);
        props.put(CastClusterConfig.CONVERTER_PATH, getConverterBase());
        config.save();

        return new ForwardResolution("/view/config_edit_inc.jsp");
    }


}
